<?php
require_once(SMARTY_DIR."Smarty.class.php");

/**
 * Clase ContentManager
 * @author chalodrv@yahoo.es
 */
class ContentManager
{
	/**
	 * Variables
	 */
	var $tpl;
	var $lang;
	var $langmsg;

	/**
	 * Constructor
	 * @param string $lang
	 */
	function __construct($lang = DEFAULT_LANGUAGE)
	{
		$this->tpl = new Smarty();
		$this->lang = $lang;
		require_once(LANG_DIR.$this->lang.".php");
		$this->langmsg = $langmsg;
	}

	/**
	 * Método initiate
	 */
	function initiate($section=DEFAULT_SECTION)
	{
		$this->tpl->assign("sectionName", $section);
		$this->tpl->assign("sectionTitle", $this->langmsg[$section]);

		// Menú
		$menuOptions = array();
		if (!in_array($section, explode(",", SECTIONS_WITHOUT_MENU))) {
			$aliases = array("home", "sections", "tours", "links", "faq", "blogentries", "content");
			foreach ($aliases as $alias) {
				$menuOptions[$alias] = array(
					"alias" => $alias,
					"name" => $this->langmsg[$alias],
					"url" => Utils::generateSEOUrl($this->lang, $alias)
				);
			}
		}
		$this->tpl->assign("menuOptions", $menuOptions);

		$this->tpl->assign("lang", $this->lang);
		$this->tpl->assign("pagetitle", PAGE_TITLE);

		$this->tpl->assign("basepath", BASE_URL);
		$this->tpl->assign("csspath", CSS_URL);
		$this->tpl->assign("jspath", JS_URL);
		$this->tpl->assign("imagespath", IMAGES_URL);
		$this->tpl->assign("uploadspath", UPLOADS_URL);

		if (isset($_SESSION["adminLoggedUserName"])) {
			$this->tpl->assign("adminLoggedUserName", $_SESSION["adminLoggedUserName"]);
			$this->tpl->assign("logoutUrl", Utils::generateSEOUrl($this->lang, "logout"));
		}
	}
	
	/**
	 * Método assign
	 * @param string $field
	 * @param string $value
	 */
	function assign($field, $value)
	{
		$this->tpl->assign($field, $value);
	}

	/**
	 * Método display
	 * @param string $templateName
	 */
	function display($templateName)
	{
		$this->tpl->display($templateName);
	}
	
	/**
	 * Método fetch
	 * @param string $templateName
	 */
	function fetch($templateName)
	{
		return $this->tpl->fetch($templateName);
	}

	/**
	 * Método multipleAssign
	 * @param array $varNames
	 */
	function multipleAssign($varNames)
	{
		if (!is_array($varNames)) {
			return false;
		} else {
			foreach ($varNames as $varName) {
				$this->assign($varName, $this->langmsg[$varName]);
			}
			return true;
		}
	}
}
?>
